package com.triptogether.receivers;

import java.util.ArrayList;
import java.util.List;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public abstract class DBObjectCreatedReceiver extends BroadcastReceiver {
	
	List<DBObjectCreatedListener> listeners;
	
	public DBObjectCreatedReceiver() {
		listeners = new ArrayList<DBObjectCreatedListener>();
	}
	
	@Override
	public void onReceive(Context context, Intent intent) {}

	
	// ////////////////////
	// Listener
	// ////////////////////
	
	protected void onDbObjectCreated(Object dbObject) {
		for (DBObjectCreatedListener listener : listeners) {
			listener.onObjectCreated(dbObject);
        }
	}
	
	public interface DBObjectCreatedListener {
		void onObjectCreated(Object dbObject);
	}
	
	public void registerToDbObejctCreatedReceiverListener(DBObjectCreatedListener listener) {
		listeners.add(listener);
	}
	
	public void unregisterToDbObjectCreatedReceiverListener(DBObjectCreatedListener listener) {
		listeners.remove(listener);
	}
	
	// ////////////////////
	// End of Listener
	// ////////////////////

}
